<?php
include_once XXF_RUNEXCEL;
class Pxy_ctl extends Ctl{
    function __construct(){
    }
    function main(array $xxfget) {
        $this::sessver();
        $type=!empty($_POST['type'])?$_POST['type']:false;
        if(!empty($xxfget['type'])){$type=$xxfget['type'];}
        if(!$type){
        	$result=xdb::getInstance()->getarray('select stime,etime,realname,pname,shiqi,p.id as pid,p.atime as ptime from peixunban as p,user u where p.bzrid=u.id and u.id='.XXF_UID);
        	$bzr=xdb::getInstance()->getarray("select id,realname from user where id in (select uid from user_groupx where gid=".(gconf('web', 'bzrid')).")");
        	//$peixunrenshu=xdb::getInstance()->getvar("select count(1) from ")
        	$this::show('pxy',compact('result','bzr'));
        }elseif ($type=="add"){
        	$array=array();
        	$array2=array();
        	$uid=$_POST['uid'];
        	$shiqi=$_POST['shiqi'];
        	$bzrid=$_POST['bzrid'];
        	$pname=$_POST['pname'];
        	$array['uid']=$uid;
        	$array['shiqi']=$shiqi;
        	$array['pname']=$pname;
        	$array['bzrid']=$bzrid;
        	$array2['shiqi']=$shiqi;
        	$array2['pname']=$pname;
        	echo xdb::getInstance()->indb('peixunban', $array, $array2);
        }elseif($type=="upzxpx"){//专项培训，特种作业
            $xls=new RunExcel();
            $xls->fromExcel($_FILES['file']['tmp_name']);
            $sh=$xls->getSheetArray();
            $y=0;
            for($i=0;$i<count($sh);$i++){
                $pid=xdb::getInstance()->getvar("select id from peixunban where shiqi like '".$sh[$i][5]."%' and pname like '".$sh[$i][2]."'");
                //echo "select id from peixunban where shiqi like '".$sh[$i][5]."%' and pname like '".$sh[$i][2]."'";exit();
                if(!_checkIdCard($sh[$i][1])){
                    continue;
                };
                $array=array();
                $array2=array();
                if($pid){
                    $array['puname']=$sh[$i][0];
                    $array['idcard']=$sh[$i][1];
                    $array['pid']=$pid;
                    $array['chengji']=$sh[$i][3];
                    $array['shicaochengji']=$sh[$i][4];
                    $array['beizhu']=$sh[$i][6];
                    $array['workunit']=$sh[$i][6];
                    $array['ptype']="专项人员";
                    $array2['idcard']=$sh[$i][1];
                    $array2['pid']=$pid;
                    if(xdb::getInstance()->indb("peixunxueyuan", $array, $array2)){
                        $y++;
                    }
                }
            }
            echo "成功".$y."条";
        }elseif($type=="downzxpxtemp"){//下载专项模板
            $xls=new RunExcel();
            $xls->createExcel();
            $xls->setHeader(array("姓名","身份证","班级（和系统一致）","理论成绩","实操成绩","年度","备注(单位名称)"));
            $xls->down("zxpxtemplet");
        }
    }
}